# coding:utf-8
# @Time    : 2021/11/29 17:38
# @Author  : Martin
from page_object.base import PageItems
from util.read_file import get_approve_data


class OfflineComeGift(PageItems):
    _base_url = "/nspas-web-in/processRoleFilter.do?businessTemplateId" \
                "=NSOA25038&comType=1"

    business_code = None

    def input_act_rule(self, option, gifts):
        self.input('name', 'privilegeRule.promotionGoods', option)
        for gift in gifts:
            index = gifts.index(gift) + 1
            self.click('xpath', '//a[@onclick="presentScopeAdd();"]')
            self.input('css selector', f'#detailedtablePresentScopeLevel_1>table:nth-child({index}) '
                                       'input[name="activityPresentScope.commodityCode"]', gift['code'])
            self.input('css selector', f'#detailedtablePresentScopeLevel_1>table:nth-child({index}) '
                                       'input[name="activityPresentScope.singleAmount"]', gift['count'])
            self.input('css selector', f'#detailedtablePresentScopeLevel_1>table:nth-child({index}) '
                                       'input[name="activityPresentScope.totalAmount"]', gift['total'])
            for supplier in gift['suppliers']:
                s_index = gift['suppliers'].index(supplier) + 1
                self.input('css selector', f'#detailedtablePresentScopeLevel_1>table:nth-child({index}) '
                                           f'input[name="activityPresentScope.supplierCode{s_index}"]', supplier)

    @staticmethod
    def get_approve_head_create():
        """
        获取总部新建审批流账号数据
        :return:
        """
        return get_approve_data('offline_come_gift', 'head', 'create')

    def input_act_show_info(self, txt):
        """
        输入活动展示信息
        :param txt:
        :return:
        """

        self.input('name', 'promotionMaster.activityDisplayInfo', txt)

    # def submit_approve(self, approve_info):
    #     self._submit_approve(approve_info, 0)

    def go_to_approve(self):
        """
        首次提交审批
        :return:
        """
        self.click('id', 'evaluateSubmitBtn')


if __name__ == '__main__':
    print(OfflineComeGift.get_approve_head_create())
